Vector Creation
Although there is no distinct vector type in , you can
pretend that there is. If your algorithm or program does not need
two dimensional arrays, then you can use matrices as one dimensioned
arrays.
When using vectors, or single dimension arrays, row matrices are
created. The simplest way to create a vector is with the `:
'
operator(s):
The first operand specifies the starting value, the second operand
specifies the last value. The optional third operand can be used to
specify an increment. If this is not specified, the default
increment is 1. Here are some examples:
> c = 1:4
c =
1 2 3 4
> d = 1:3:0.5
d =
1 1.5 2 2.5 3
> e = 1:3:0.6
e =
1 1.6 2.2 2.8
The other way to generate a vector is to simply specify it using the
matrix form with one of the dimensions set to 1. This method allows
you to generate a vector containing any elements, not just an evenly
spaced sequence. Just remember that doesn't know anything
about vectors — they are just a matrix where one of the dimensions
is 1. Some functions do something slightly different if they come
across a matrix that is the vector form, but they are really just a
notational convenience, not a fundamental change, and anything that
applies to a matrix also applies to something that we treat as a
vector.